// 測試求職報名頁面的邏輯流程
// 根據用戶提供的最新數據格式進行測試

// 模擬 API 返回的數據格式
const mockApiResponse = {
  code: 200,
  data: {
    changeSignup: true, // 是否展示替換崗位信息
    originally: { // 原崗位信息
      company: "原企業名稱",
      customerName: "原企業客戶名",
      position: "原崗位名稱",
      jobTitle: "原崗位標題",
      salary: "原工資",
      workPrice: "原工價",
      address: "原地址",
      hireRecruitUseId: "原招聘ID",
      hireRecruitUseEntryId: "原招聘條目ID",
      createdAt: "2025-01-20T10:00:00Z"
    }
  }
}

// 模擬從首頁傳遞過來的崗位信息
const mockJobInfoFromHomepage = {
  id: "job123",
  title: "新崗位標題",
  salary: "新工資",
  company: "新企業名稱",
  customerName: "新企業客戶名",
  position: "新崗位名稱",
  employmentModel: "派遣工",
  useWorkType: "全職",
  hireRecruitUseId: "new_recruit_id",
  hireRecruitUseEntryId: "new_entry_id",
  address: "新地址"
}

// 測試數據映射邏輯
function testDataMapping() {
  console.log('=== 測試求職報名頁面數據映射邏輯 ===')
  
  // 1. 檢查 changeSignup 字段
  const hasExistingSignup = mockApiResponse.data.changeSignup || false
  console.log('1. changeSignup 字段:', hasExistingSignup)
  console.log('   - 當 changeSignup 為 true 時，顯示崗位對比頁面')
  console.log('   - 當 changeSignup 為 false 時，顯示普通報名頁面')
  
  // 2. 檢查原崗位信息映射
  if (hasExistingSignup && mockApiResponse.data.originally) {
    const previousSignup = {
      company: mockApiResponse.data.originally.company || mockApiResponse.data.originally.customerName || '',
      position: mockApiResponse.data.originally.position || mockApiResponse.data.originally.jobTitle || '',
      salary: mockApiResponse.data.originally.salary || mockApiResponse.data.originally.workPrice || '',
      address: mockApiResponse.data.originally.address || '',
      hireRecruitUseId: mockApiResponse.data.originally.hireRecruitUseId || '',
      hireRecruitUseEntryId: mockApiResponse.data.originally.hireRecruitUseEntryId || '',
      createdAt: mockApiResponse.data.originally.createdAt || Date.now()
    }
    
    console.log('2. 原崗位信息映射:')
    console.log('   - 企業:', previousSignup.company)
    console.log('   - 崗位:', previousSignup.position)
    console.log('   - 工價:', previousSignup.salary)
    console.log('   - 地址:', previousSignup.address)
  }
  
  // 3. 檢查新崗位信息（來自首頁）
  console.log('3. 新崗位信息（來自首頁）:')
  console.log('   - 企業:', mockJobInfoFromHomepage.company || mockJobInfoFromHomepage.customerName)
  console.log('   - 崗位:', mockJobInfoFromHomepage.position || mockJobInfoFromHomepage.title)
  console.log('   - 工價:', mockJobInfoFromHomepage.salary)
  console.log('   - 地址:', mockJobInfoFromHomepage.address)
  
  // 4. 檢查頁面顯示邏輯
  console.log('4. 頁面顯示邏輯:')
  if (hasExistingSignup) {
    	console.log('   - 步骤1标题: 确认更换企业信息')
	console.log('   - 按钮文本: 确认变更信息并下一步')
    console.log('   - 顯示: 原崗位 vs 新崗位對比卡片')
  } else {
    	console.log('   - 步骤1标题: 确认身份信息')
    console.log('   - 按鈕文本: 下一步')
    	console.log('   - 显示: 岗位详情卡片 + 个人信息确认')
  }
  
  // 5. 檢查數據字段映射
  console.log('5. 數據字段映射:')
  console.log('   - company 優先使用 company，備用 customerName')
  console.log('   - position 優先使用 position，備用 jobTitle')
  console.log('   - salary 優先使用 salary，備用 workPrice')
  console.log('   - 所有字段都有備用值，避免顯示 undefined')
}

// 執行測試
testDataMapping()

// 測試不同的 changeSignup 值
console.log('\n=== 測試不同 changeSignup 值的效果 ===')

// 測試 changeSignup = false
const testChangeSignupFalse = {
  ...mockApiResponse,
  data: {
    ...mockApiResponse.data,
    changeSignup: false
  }
}

console.log('changeSignup = false:')
	console.log('- 显示岗位详情卡片')
	console.log('- 显示个人信息确认')
	console.log('- 步骤标题: 确认身份信息')

// 測試 changeSignup = true
const testChangeSignupTrue = {
  ...mockApiResponse,
  data: {
    ...mockApiResponse.data,
    changeSignup: true
  }
}

console.log('\nchangeSignup = true:')
console.log('- 顯示原崗位信息卡片')
console.log('- 顯示新崗位信息卡片')
	console.log('- 步骤标题: 确认更换企业信息')
	console.log('- 按钮文本: 确认变更信息并下一步')

console.log('\n=== 測試完成 ===')
